﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WS.EKA.Business.Dal;
using Newtonsoft.Json;

namespace WS.EKA.Web.UI.Ajax
{
    /// <summary>
    /// Summary description for DailyEventReport
    /// </summary>
    public class DailyEventReport : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string requestType = context.Request.QueryString["ReportType"];

            ReportType enumType = ReportType.None;
            Enum.TryParse<ReportType>(requestType, out enumType);

            int invervalMinutes = 0;
            int.TryParse(context.Request.QueryString["InvervalMinutes"], out invervalMinutes);
            if (invervalMinutes <= 0)
                invervalMinutes = 10;

            int hoursRegion = 0;
            int.TryParse(context.Request.QueryString["HoursRegion"], out hoursRegion);
            if (hoursRegion <= 0)
                hoursRegion = 6;

            object ret = null;
            switch (enumType)
            {
                #region daily
                case ReportType.DailyL_TLLT_Count:
                    ret = EventReportAccess.GetDailyLTTLCount();
                    break;
                case ReportType.Daily_TLLT_Trend:
                    ret = EventReportAccess.GetDailyLTTLTrendStatistics(invervalMinutes, hoursRegion);
                    break;
                case ReportType.Daily_TLLT_Trend_Before:
                    ret = EventReportAccess.GetDailyLTTLTrendStatisticsBefore(invervalMinutes, hoursRegion);
                    break;
                case ReportType.DailyL_ED_Count:
                    ret = EventReportAccess.GetDailyEDCount();
                    break;
                case ReportType.Daily_ED_Trend:
                    ret = EventReportAccess.GetDailyEDTrendStatistics(invervalMinutes, hoursRegion);
                    break;
                case ReportType.Daily_ED_Trend_Before:
                    ret = EventReportAccess.GetEDTrendStatisticsBefore(invervalMinutes, hoursRegion);
                    break;
                #endregion

                #region weekly
                case ReportType.Weekly_TLLT_Count:
                    ret = EventReportAccess.GetWeeklyTLLTCount();
                    break;

                case ReportType.Weekly_TLLT_Trend:
                    ret = EventReportAccess.GetWeeklyTLLTStatisticsOfCrrent();
                    break;
                case ReportType.Weekly_TLLT_Trend_Before:
                    ret = EventReportAccess.GetWeeklyTLLTStatisticsOfBefore();
                    break;
                case ReportType.Weekly_ED_Count:
                    ret = EventReportAccess.GetWeeklyEDCount();
                    break;
                case ReportType.Weekly_ED_Trend:
                    ret = EventReportAccess.GetWeeklyEDStatisticsOfCrrent();
                    break;
                case ReportType.Weekly_ED_Trend_Before:
                    ret = EventReportAccess.GetWeeklyEDStatisticsOfBefore();
                    break;
                #endregion
            }
            context.Response.ContentType = "application/json";
            context.Response.Write(JsonConvert.SerializeObject(ret));

        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }



    }

    public enum ReportType
    {
        None,
        DailyL_TLLT_Count,
        Daily_TLLT_Trend,
        Daily_TLLT_Trend_Before,

        DailyL_ED_Count,
        Daily_ED_Trend,
        Daily_ED_Trend_Before,

        Weekly_TLLT_Count,
        Weekly_TLLT_Trend,
        Weekly_TLLT_Trend_Before,

        Weekly_ED_Count,
        Weekly_ED_Trend,
        Weekly_ED_Trend_Before,
    }
}